//////////////////////////////////////////////////////////////////////////////////////////////////
// 
// File: cube.h
// 
// Author: Frank Luna (C) All Rights Reserved
//
// System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0 
//
// Desc: Provides an interface to create and render a cube.
//          
//////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef __cubeH__
#define __cubeH__

#include <d3dx9.h>
#include "ResManager.h"
#include "CubeStatus.h"
#include "Formula.h"

class Cube
{
public:
	Cube();
	~Cube();

	HRESULT Initial(IDirect3DDevice9* pDevice);
	HRESULT Destroy();
	HRESULT Draw(D3DXMATRIX* world, D3DMATERIAL9* mtrl, IDirect3DTexture9* tex,double fTime, float fElapsedTime);	

    // change status according to the formula
    void    DoFormula(Formula* pFormula);

    D3DXMATRIX GetPosMatrix(){return m_matPosition;}
	void Move(D3DXMATRIX matWorld);
	void Rotate(D3DXMATRIX matWorld);

    void SetCubeStatus(int x, int y, int z, int level){m_status.Initial(x, y, z, level);}
    CubeStatus* GetStatus(){return &m_status;}
    CubeIndex*  GetIndex() {return m_status.GetIndex();}

protected:	
	IDirect3DDevice9*       _device;
	IDirect3DVertexBuffer9* _vb;
	IDirect3DIndexBuffer9*  _ib;
	D3DXMATRIX m_matPosition;    // Record final position matrix of this cube.

	int m_nIndex;
	D3DXVECTOR3 m_vecPosition;
	CubeStatus  m_status;       // Record the status of this cube.
	
};

extern ResManager g_resMgr;

#endif //__cubeH__